<?php
/**
 * Created by PhpStorm.
 * User: fengtian
 * Date: 15-4-1
 * Time: 下午2:45
 */
?>
<link rel="stylesheet" href="<?php echo URL::base() ?>media/vendor/css/style.css" type="text/css" media="all"/>
<link rel="stylesheet" href="<?php echo URL::base() ?>media/vendor/artdialog/skins/default.css" type="text/css"
      media="all"/>
<link href="<?php echo URL::base() ?>media/vendor/css/ui-lightness/jquery-ui-1.10.4.custom.css" rel="stylesheet">
<link href="<?php echo URL::base() ?>media/vendor/fixtable/css/component.css" rel="stylesheet">
<link href="<?php echo URL::base() ?>media/vendor/fixtable/css/normalize.css" rel="stylesheet">
<link href="<?php echo URL::base() ?>media/vendor/css/jquery-ui-timepicker-addon.min.css" rel="stylesheet">
<script src="<?php echo URL::base() ?>media/vendor/js/jquery-1.10.2.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/jquery-ui-1.10.4.custom.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/jquery-ui-timepicker-addon.min.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/jquery-ui-timepicker-zh-CN.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/jquery.ui.datepicker-zh-TW.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/Validform_v5.3.2_ncr_min.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/artdialog/jquery.artDialog.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/artdialog/plugins/iframeTools.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/jquery.printPage.js"></script>
<script src="<?php echo URL::base() ?>media/js/jquery.form.js"></script>
<style>
    .table td, .table th {
        text-align: center;
    }

    .form-horizontal .control-label {
        width: 100px;
    }

    .form-horizontal .controls {
        margin-left: 110px;
    }

    a.xiazai:hover {
        text-decoration: none;
    }

    table tbody tr:nth-child(2n) {
        background-color: #f5f5f5;
    }

    .table th, .table td {
        border: 1px solid #ffffff;
    }

    .gy-navtent2-input label {
        width: 120px;
        text-align: right;
    }

    .gy-navtent2-input {
        margin-bottom: 10px;
    }

</style>

<div class="gy-navtent2">
    <form class="form-inline" action="<?php echo URL::base() ?>checkstock/active" method="get">
        <div class="gy-navtent2-input">
            <label>平台：</label>
            <select class="form-control input-sm span2" name="stage">
                <option>全部</option>
                <option value="1" <?php if(isset($stage)&&$stage==1){
                    echo "selected";
                } ?>>ebay
                </option>
                <option value="2" <?php if(isset($stage)&&$stage==2){
                    echo "selected";
                } ?>>smt
                </option>
                <option value="3" <?php if(isset($stage)&&$stage==3){
                    echo "selected";
                } ?>>amz
                </option>
                <option value="4" <?php if(isset($stage)&&$stage==4){
                    echo "selected";
                } ?>>wish
                </option>
            </select>
        </div>
        <div class="gy-navtent2-input">
            <label>状态：</label>
            <select class="form-control input-sm span2" name="status">
                <option>全部</option>
                <option value="1" <?php if(isset($status)&&$status==1){
                    echo "selected";
                } ?>>开启
                </option>
                <option value="2" <?php if(isset($status)&&$status==0){
                    echo "selected";
                } ?>>关闭
                </option>
            </select>
        </div>
        <div class="gy-navtent2-input">
            <label>活动时间：</label>
            <input type="text" class="date span2" name="start_time" value="<?php echo isset($begin)?$begin:'' ?>"
                   placeholder="开始时间" readonly="readonly"/>
            <input type="text" class="date span2" name="end_time" value="<?php echo isset($end)?$end:'' ?>"
                   placeholder="结束时间" readonly="readonly"/>
            <input type="submit" class="btn btn-info" value="查询"/>
            <input type="button" class="btn btn-success add_active" value="添加活动"/>
        </div>
    </form>
    <div class="active_content">
        <table class="table table1 table-bordered" style="border-collapse: collapse;">
            <thead>
            <tr style="background-color:#4EA392;color:#fff; font-weight:bold;">
                <th>序号</th>
                <th>平台</th>
                <th>开始时间</th>
                <th>结束时间</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            <?php
            if(isset($result)){
                foreach($result as $k => $v):?>
                    <tr>
                        <td><?php echo ++$k; ?> </td>
                        <td><?php if($v['stage']==1){
                                echo "ebay";
                            }elseif($v['stage']==2){
                                echo "smt";
                            }elseif($v['stage']==3){
                                echo "amz";
                            }elseif($v['stage']==4){
                                echo "wish";
                            };?> </td>
                        <td><?php echo $v['begin']; ?> </td>
                        <td><?php echo $v['end']; ?> </td>
                        <td>
                            <input type="hidden" value="<?php echo $v['id']; ?>"/>
                            <input type="button" class="btn btn-success update_active" value="修改">
                            <?php if($v['status']==1){
                                echo "<input type='button' class='btn btn-inverse close_active' value='关闭'>";
                            }else{
                                echo "<input type='button' class='btn btn-info open_active' value='开启'>";
                            }
                            ?>
                            <input type="button" class="btn btn-danger add_sku" value="添加sku">

                            <div class="btn btn-success">
                                <a href="<?php echo URL::base() ?>checkstock/upload_sku?id=<?php echo $v['id']; ?>">批量上传sku</a>
                            </div>
                        </td>
                    </tr>
                <?php endforeach;
            }
            ?>
            </tbody>

        </table>
        <div>
            <?php if(isset($pagination)){
                echo $pagination;
            }
            ?>
        </div>
    </div>
</div>

<script>
    $(function () {
        $(".date").datetimepicker({
            dateFormat: 'yy-mm-dd',
            timeFormat: 'HH:mm:ss'
        });

        $('.close_active').on('click', function () {
            var id = $(this).siblings("input").eq(0).val();
            art.dialog.confirm('你确定要关闭这个活动么?', function () {
                $.get("<?php echo URL::base()?>checkstock/close_active",
                    {id: id},
                    function (data) {
                        var obj = jQuery.parseJSON(data);
                        art.dialog.alert(obj.info);
                        window.location.reload();
                    }
                )
            })
        });

        $('.open_active').on('click', function () {
            var id = $(this).siblings("input").eq(0).val();
            art.dialog.confirm('你确定要开启这个活动么?', function () {
                $.get("<?php echo URL::base()?>checkstock/open_active",
                    {id: id},
                    function (data) {
                        var obj = jQuery.parseJSON(data);
                        art.dialog.alert(obj.info);
                        window.location.reload();
                    }
                )
            })
        });

        $('.update_active').on('click', function () {
            var id = $(this).siblings("input").eq(0).val();
            $.get("<?php echo URL::base()?>checkstock/update_active",
                {id: id},
                function (data) {
                    var obj = jQuery.parseJSON(data);
                    art.dialog({
                        title: '详情',
                        lock: true,
                        content: obj.view
                    })
                }
            )
        });

        $('.add_active').on('click', function () {
            $.get("<?php echo URL::base()?>checkstock/add_active",
                {},
                function (data) {
                    var obj = jQuery.parseJSON(data);
                    art.dialog({
                        title: '详情',
                        lock: true,
                        content: obj.view
                    })
                }
            )
        });

        $('.add_sku').on('click', function () {
            var id = $(this).siblings("input").eq(0).val();
            $.get("<?php echo URL::base()?>checkstock/add_sku",
                {id: id},
                function (data) {
                    var obj = jQuery.parseJSON(data);
                    art.dialog({
                        title: '详情',
                        lock: true,
                        content: obj.view
                    })
                }
            )
        });

    })
</script>